package com.twu.biblioteca;

import static junit.framework.TestCase.*;
import static org.mockito.Mockito.*;

import com.twu.biblioteca.*;
import org.junit.Before;
import org.junit.Test;

import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayList;

import static org.junit.Assert.assertEquals;


public class BibliotecaAppTest {

    private PrintStream printStream;
    private BufferedReader bufferedReader;
    private BibliotecaApp bibliotecaApp;
    private BookGetter bookGetter;
    private Book b1;
    private Book b2;
    private Input input;
    private Output output;
    private MovieGetter movieGetter;

    @Before
    public void setUp() throws Exception {
       printStream = mock(PrintStream.class);
       bufferedReader  = mock(BufferedReader.class);
       b1 = mock(Book.class);
       b2 = mock(Book.class);
       bookGetter = mock(BookGetter.class);
       input = mock(Input.class);
       output = mock(Output.class);
       movieGetter = mock(MovieGetter.class);

       bibliotecaApp = new BibliotecaApp(bookGetter, input, output, movieGetter);
    }







//    @Test
//    public void shouldReserveBookForCollection() {
//        Book unReservedBook = mock(Book.class);
//        assertTrue(unReservedBook.reserve());
//
//        Book reservedBook = unReservedBook;
//        assertFalse(reservedBook.reserve());
//    }



//    @Test
//    public void shouldNotifyIfReservedBook() throws Exception {
//        when(b1.reserve()).thenReturn(true);
//        bibliotecaApp.reserveBook();
//        when(b1.reserve()).thenReturn(false);
//        assertFalse(bibliotecaApp.reserveBook());
//        verify(printStream).println("Sorry we don't have that book yet.");
//    }


    @Test
    public void shouldHaveOptionMenuAppear() {

        ArrayList<String> options = new ArrayList<String>();
        options.add("See List of Books") ;
        options.add("Reserve Book")     ;
        options.add("Check Membership");
        options.add("See List of Movies");

        bibliotecaApp.showMenuOptions();
        verify(output).printMenuOptions(options);
    }



    @Test
    public void shouldSelectValidMenuOptionWhenOptionSelectionOutOfBounds() throws Exception {
        bibliotecaApp.processMenuOption(100);
        verify(output).printValidOptionPrompt();
    }

    @Test
    public void shouldReturnInvalidMenuOptionWhenNumberLessThanZero() throws Exception{
        bibliotecaApp.processMenuOption(-1);
        verify(output).printValidOptionPrompt();
    }

    @Test
    public void shouldSelectShowBooks() throws Exception {
        bibliotecaApp.processMenuOption(0);
        verify(bookGetter).showBooks();

    }

    @Test
    public void shouldSelectBookReservation() throws Exception{
        bibliotecaApp.processMenuOption(1);
        verify(bookGetter).reserveBook();
    }

    @Test
    public void shouldDisplayTalkToLibrarianMessageWhenOption2Picked() throws Exception {
        bibliotecaApp.processMenuOption(2);
        verify(bookGetter).checkMembership();
    }

    @Test
    public void shouldDisplayListOfMoviesWhenOption3Picked() {
        bibliotecaApp.processMenuOption(3);
        verify(movieGetter).showMovies();
    }


}
